﻿using System.Windows.Input;
using WPFTemplateLib.Mvvm;
using WPFTemplateLib.WpfHelpers;

namespace WpfAnimationDemo.ViewModels
{
    public class MyViewModelBase : ViewModelBase
    {
        #region 处理载入事件

        /// <summary>
        /// 是否是第一次载入
        /// </summary>
        private bool _isFirstLoad = true;

        #region [命令] 载入
        private ICommand _LoadedCmd;
        public ICommand LoadedCmd => _LoadedCmd ??= new RelayCommand<object>(ExecuteLoadedCmd);
        private void ExecuteLoadedCmd(object para)
        {
            OnLoaded(_isFirstLoad);

            if (_isFirstLoad)
            {
                _isFirstLoad = false;
            }
        }
        #endregion

        /// <summary>
        /// 载入完成时的处理方法
        /// </summary>
        /// <remarks>
        /// 需在 Loaded 事件时调用 <see cref="LoadedCmd"/> 命令，此方法才有效。
        /// </remarks>
        /// <param name="isFirst">是否是第一次载入</param>
        protected virtual void OnLoaded(bool isFirst) { }

        #endregion
    }
}
